package com.acwing.partition10;

import java.io.*;
import java.util.Arrays;
import java.util.Comparator;

/**
 * @author `RKC`
 * @date 2021/12/2 20:44
 */
public class AC907区间覆盖 {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] s = reader.readLine().split(" ");
        int n = 0, left = Integer.parseInt(s[0]), right = Integer.parseInt(s[1]);
        n = Integer.parseInt(reader.readLine().split(" ")[0]);
        int[][] intervals = new int[n][2];
        for (int i = 0; i < n; i++) {
            s = reader.readLine().split(" ");
            intervals[i][0] = Integer.parseInt(s[0]);
            intervals[i][1] = Integer.parseInt(s[1]);
        }
        writer.write(greedy(new int[]{left, right}, intervals) + "\n");
        writer.flush();
    }

    private static int greedy(int[] coverIntervals, int[][] intervals) {
        //同区间合并差不多，只不过区间合并是合并的所有区间，而该题是合并指定范围区间
        Arrays.sort(intervals, Comparator.comparingInt(o -> o[0]));
        int answer = 0;
        for (int i = 0; i < intervals.length; i++) {
            int j = i, end = -0x3f3f3f3f;
            //找到所有目前在目标区间左端点的所有区间，并取这些区间的最大右端点
            while (j < intervals.length && intervals[j][0] <= coverIntervals[0]) {
                end = Math.max(end, intervals[j][1]);
                j++;
            }
            answer++;
            //当前区间连目标区间的起点都无法覆盖，说明没有覆盖方案；特判一下，如果j已经指向了最后一个区间，但是这个时候并没有覆盖完目标区间，说明也没有覆盖方案
            if (end < coverIntervals[0] || (j == intervals.length && end < coverIntervals[1])) return -1;
            //已经覆盖完毕，直接退出循环
            if (end >= coverIntervals[1]) break;
            coverIntervals[0] = end;
            i = j - 1;
        }
        return answer;
    }
}
